package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyPNGImage;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;

public class PNGImageImpl {

    public Element createElement(String url, int width, int height, int opacity) {
        Element result = DOM.createImg();
        DOM.setElementProperty(result, "src", url);
        DOM.setElementPropertyInt(result, "width", width);
        DOM.setElementPropertyInt(result, "height", height);
        DOM.setStyleAttribute(result, "opacity", "" + ((double) opacity / 100));
        DOM.setStyleAttribute(result, "filter", "alpha( opacity = " + opacity + " )");
        DOM.setStyleAttribute(result, "mozOpacity", "" + ((double) opacity / 100));
        return result;
    }

    public void formatElement(FPNGImage image, int width, int height, int opacity) {
        DOM.setElementPropertyInt(image.getElement(), "width", width);
        DOM.setElementPropertyInt(image.getElement(), "height", height);
        DOM.setStyleAttribute(image.getElement(), "opacity", "" + ((double) opacity / 100));
        DOM.setStyleAttribute(image.getElement(), "filter", "alpha( opacity = " + opacity + " )");
        DOM.setStyleAttribute(image.getElement(), "mozOpacity", "" + ((double) opacity / 100));
    }

    public String getUrl(FPNGImage image) {
        return DOM.getElementProperty(image.getElement(), "src");
    }

}